home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / C / Screens / ColourBars.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-04  |  3.4 KB  |  96 lines

  1. /*
  2. ** Colourlist Example
  3. ** ------------------
  4. ** Colourlists are those nice colour gradients used in demos and games,
  5. ** usually  sitting in the background of your screen.  Colourlists are mostly
  6. ** good for getting more colours on screen than what is really available.
  7. ** Although  GMS allows you to do other screen effects based on raster lines,
  8. ** we'll just stick to changing colours in this demo.
  9. ** 
  10. ** You can move the green colour bar by moving the mouse up and down.
  11. ** You will notice that if you move the green bar into the upper red bar,
  12. ** your bar will disappear and leave some green lines at the end of the red
  13. ** bar.  This is because:
  14. ** 
  15. **   WAITLINE  95        ;Wait for line 95
  16. **   WAITLINE 100        ;Wait for line 100
  17. **   WAITLINE  90        ;Wait for line 90 <--Error! 
  18. ** 
  19. ** Is illegal.  The monitor beam travels down the screen, and so the
  20. ** UpdateRasterlist() routine will expect all lines to be in sequential order.
  21. ** Moving two colourbars into each other breaks this rule, causing the wait
  22. ** command to be ignored.  If you want to get around this (green bar appears
  23. ** on top of red bar), you will have to have just one large colourlist and sort
  24. ** your colours before each call to UpdateRasterlist().
  25. ** 
  26. ** Similarly if you move the colour bar too far down the screen the hardware
  27. ** won't like it because lines > 311 don't exist.  It's up to you to be
  28. ** responsible enough to stop this from happening!
  29. ** 
  30. ** Press the left mouse button to exit the demo.
  31. */
  32.  
  33. #include <proto/games.h>
  34.  
  35. extern struct GMSBase *GMSBase;
  36. ULONG  _XCEXIT = NULL;
  37. APTR   PREFSNAME = DEFAULT;
  38.  
  39. LONG ColourBar1[] = {
  40.      0x100000,0x200000,0x300000,0x400000,0x500000,0x600000,0x700000,0x800000,0x900000,0xa00000,
  41.      0xb00000,0xc00000,0xd00000,0xe00000,0xe00000,0xe00000,0xd00000,0xc00000,0xb00000,0xa00000,
  42.      0x900000,0x800000,0x700000,0x600000,0x500000,0x400000,0x300000,0x200000,0x100000,0x000000,
  43.      -1
  44. };
  45.  
  46. LONG ColourBar2[] = {
  47.      0x001000,0x002000,0x003000,0x004000,0x005000,0x006000,0x007000,0x008000,0x009000,0x00a000,
  48.      0x00b000,0x00c000,0x00d000,0x00e000,0x00f000,0x00e000,0x00d000,0x00c000,0x00b000,0x00a000,
  49.      0x009000,0x008000,0x007000,0x006000,0x005000,0x004000,0x003000,0x002000,0x001000,0x000000,
  50.      -1
  51. };
  52.  
  53. LONG ColourBar3[] = {
  54.      0x000010,0x000020,0x000030,0x000040,0x000050,0x000060,0x000070,0x000080,0x000090,0x0000a0,
  55.      0x0000b0,0x0000c0,0x0000d0,0x0000e0,0x0000f0,0x0000e0,0x0000d0,0x0000c0,0x0000b0,0x0000a0,
  56.      0x000090,0x000080,0x000070,0x000060,0x000050,0x000040,0x000030,0x000020,0x000010,0x000000,
  57.      -1
  58. };
  59.  
  60. ULONG Rasterlist[] = {
  61.      COLOURLIST(000,3,00,&ColourBar1),   /* Line, Skip, Colnum, ColourList */
  62.      COLOURLIST(160,1,00,&ColourBar2),   /* Line, Skip, Colnum, ColourList */
  63.      COLOURLIST(230,1,00,&ColourBar3),   /* Line, Skip, Colnum, ColourList */
  64.      RASTEND
  65. };
  66.  
  67. void main(void)
  68. {
  69.    struct GameScreen *GameScreen;
  70.    WORD   barpos = 160;
  71.    ULONG  mouse;
  72.  
  73.    if (GameScreen = AddScreenTags(TAGS_GAMESCREEN,NULL,
  74.        GSA_Rasterlist,&Rasterlist,
  75.        GSA_Planes,1,
  76.        GSA_Attrib,BLKBDR,
  77.        TAGEND)) {
  78.  
  79.       ShowScreen(GameScreen);
  80.       InitJoyPorts();
  81.  
  82.       do {
  83.          mouse = ReadJoyPort(JPORT1,JT_ZBXY);
  84.          barpos += (BYTE)mouse;
  85.          if (barpos < 0) barpos = 0;
  86.          if (barpos > 226) barpos = 226;
  87.          Rasterlist[4] = (Rasterlist[4] & 0xffff0000)|barpos;
  88.          UpdateRasterLines(GameScreen);
  89.          WaitVBL();
  90.       } while (!(mouse & MB_LMB));
  91.  
  92.    DeleteScreen(GameScreen);
  93.    }
  94. }
  95.  
  96.